package com.google.code.jira.script.service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

import com.atlassian.configurable.ValuesGenerator;

public class ScriptEngineNameGenerator implements ValuesGenerator {

	public Map getValues(Map userParams) {
		Map map = new HashMap();

		ScriptEngineManager manager = new ScriptEngineManager();
		List factories = manager.getEngineFactories();
		if (factories != null && factories.size() > 0) {
			for (Iterator iterator = factories.iterator(); iterator.hasNext();) {
				ScriptEngineFactory factory = (ScriptEngineFactory) iterator.next();
				map.put(factory.getEngineName(), factory.getEngineName());
			}
		}

		return map;
	}

}
